//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lbank.spiderflow.core.executor.shape;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Util {
    public static String encrypt(String srcStr) {
        if (srcStr == null) {
            return null;
        } else {
            MessageDigest messageDigest = null;

            try {
                messageDigest = MessageDigest.getInstance("MD5");
                messageDigest.reset();
                messageDigest.update(srcStr.getBytes(StandardCharsets.UTF_8));
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }

            assert messageDigest != null;

            byte[] byteArray = messageDigest.digest();
            StringBuilder md5StrBuff = new StringBuilder();

            for(byte b : byteArray) {
                if (Integer.toHexString(255 & b).length() == 1) {
                    md5StrBuff.append("0").append(Integer.toHexString(255 & b));
                } else {
                    md5StrBuff.append(Integer.toHexString(255 & b));
                }
            }

            return md5StrBuff.toString();
        }
    }
}
